﻿using System;
using System.Collections.Generic;
using Microsoft.Office.Project.Server.Library;
using MSPE.Public.FOSS.AutoStatusPlus.Common;

namespace MSPE.Public.FOSS.AutoStatusPlus.TimerJob
{
    internal class Status
    {
        /// <summary>
        /// Get list of assignments to submit
        /// </summary>
        /// <param name="timesheetDs">Timesheet dataset</param>
        /// <param name="appLog"></param>
        /// <param name="logEvents"></param>
        /// <param name="processBlankLines"></param>
        /// <returns>List of assignements</returns>
        public static List<Guid> SubmitStatus(TimesheetSvc.TimesheetDataSet timesheetDs, AppLog appLog, bool logEvents, bool processBlankLines)
        {
            List<Guid> _assignments = new List<Guid>();
            StatusingSvc.StatusingDataSet _statDs = new StatusingSvc.StatusingDataSet();

            for (int i = 0; i < timesheetDs.Lines.Count; i++)
            {
                if ((timesheetDs.Lines[i].TS_LINE_VALIDATION_TYPE == (int)TimesheetEnum.ValidationType.Verified) &&
                    ((processBlankLines && timesheetDs.Lines[i].TS_LINE_ACT_SUM_VALUE >= 0) || 
                    (!processBlankLines && timesheetDs.Lines[i].TS_LINE_ACT_SUM_VALUE > 0)))
                {
                    _assignments.Add(timesheetDs.Lines[i].ASSN_UID);
                    if (logEvents)
                    {
                        decimal _hours = timesheetDs.Lines[i].TS_LINE_ACT_SUM_VALUE / 60000;
                        appLog.WriteLine(string.Format("\tTimesheet line: {0}; Project: {1}; Assignement: {2}; Actual Work: {3}", i,
                            timesheetDs.Lines[i].TS_LINE_CACHED_PROJ_NAME,
                            timesheetDs.Lines[i].TS_LINE_CACHED_ASSIGN_NAME,
                            _hours.ToString("N2")));
                    } // End if
                } // End if
            } // End for

            return _assignments;
        } // SubmitStatus()
    }
}
